This requires no free() calls and is just better.
{
OstreeCheckoutPrivate *priv = GET_PRIVATE (self);
gboolean ret = FALSE;
- char *path = NULL;
+ const char *path = NULL;
char *temp_path = NULL;
char *rel_temp_path = NULL;
GFile *temp_copy = NULL;
GPtrArray *args = NULL;
int estatus;
- path = g_file_get_path (trigger);
+ path = ot_gfile_get_path_cached (trigger);
basename = g_path_get_basename (path);
args = g_ptr_array_new ();
}
else
{
- g_ptr_array_add (args, path);
+ g_ptr_array_add (args, (char*)path);
g_ptr_array_add (args, NULL);
}
if (requires_chroot && temp_path)
(void)unlink (temp_path);
- g_free (path);
g_free (basename);
g_free (temp_path);
g_free (rel_temp_path);
GError **error)
{
gboolean ret = FALSE;
- char *path = NULL;
+ const char *path = NULL;
GFileInfo *finfo = NULL;
GFileInputStream *instream = NULL;
gboolean pack_builder_initialized = FALSE;
GVariant *xattrs = NULL;
gsize bytes_written;
- path = g_file_get_path (file);
+ path = ot_gfile_get_path_cached (file);
finfo = g_file_query_info (file, "standard::type,standard::size,standard::is-symlink,standard::symlink-target,unix::*",
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
ret = TRUE;
out:
- g_free (path);
g_clear_object (&finfo);
g_clear_object (&instream);
if (xattrs)
static gboolean
set_error_noent (GFile *self, GError **error)
{
- char *path = g_file_get_path (self);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
- "No such file or directory: %s", path);
- g_free (path);
+ "No such file or directory: %s",
+ ot_gfile_get_path_cached (self));
return FALSE;
}
ostree_repo_file_get_uri (GFile *file)
{
OstreeRepoFile *self = OSTREE_REPO_FILE (file);
- char *path;
+ const char *path;
char *uri_path;
char *ret;
- path = g_file_get_path (file);
+ path = ot_gfile_get_path_cached (file);
uri_path = g_filename_to_uri (path, NULL, NULL);
- g_free (path);
g_assert (g_str_has_prefix (uri_path, "file://"));
ret = g_strconcat ("ostree://", self->commit, uri_path+strlen("file://"), NULL);
g_free (uri_path);
GFile *descendant)
{
const char *remainder;
- char *parent_path;
- char *descendant_path;
+ const char *parent_path;
+ const char *descendant_path;
- parent_path = g_file_get_path (parent);
- descendant_path = g_file_get_path (descendant);
+ parent_path = ot_gfile_get_path_cached (parent);
+ descendant_path = ot_gfile_get_path_cached (descendant);
remainder = match_prefix (descendant_path, parent_path);
- g_free (parent_path);
- g_free (descendant_path);
if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
return TRUE;
return FALSE;
GFile *descendant)
{
const char *remainder;
- char *parent_path;
- char *descendant_path;
+ const char *parent_path;
+ const char *descendant_path;
- parent_path = g_file_get_path (parent);
- descendant_path = g_file_get_path (descendant);
+ parent_path = ot_gfile_get_path_cached (parent);
+ descendant_path = ot_gfile_get_path_cached (descendant);
remainder = match_prefix (descendant_path, parent_path);
- g_free (parent_path);
- g_free (descendant_path);
if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
return g_strdup (remainder + 1);
if (g_str_has_prefix (rev, "ref: "))
{
GFile *ref;
- char *ref_path;
+ const char *ref_path;
char *ref_sha256;
gboolean subret;
ref = g_file_resolve_relative_path (priv->local_heads_dir, rev + 5);
- ref_path = g_file_get_path (ref);
+ ref_path = ot_gfile_get_path_cached (ref);
subret = parse_rev_file (self, ref_path, &ref_sha256, error);
g_clear_object (&ref);
- g_free (ref_path);
if (!subret)
{
char *ret_rev = NULL;
GFile *child = NULL;
GFile *origindir = NULL;
- char *child_path = NULL;
+ const char *child_path = NULL;
GError *temp_error = NULL;
GVariant *commit = NULL;
else if (slash == NULL)
{
child = g_file_get_child (priv->local_heads_dir, rev);
- child_path = g_file_get_path (child);
+ child_path = ot_gfile_get_path_cached (child);
}
else
{
}
child = g_file_get_child (priv->remote_heads_dir, rev);
- child_path = g_file_get_path (child);
+ child_path = ot_gfile_get_path_cached (child);
}
if (!ot_util_gfile_load_contents_utf8 (child, NULL, &ret_rev, NULL, &temp_error))
g_free (tmp2);
g_clear_object (&child);
g_clear_object (&origindir);
- g_free (child_path);
g_free (ret_rev);
return ret;
}
GError *temp_error = NULL;
GFileEnumerator *enumerator = NULL;
GFileInfo *file_info = NULL;
- char *dirpath = NULL;
+ const char *dirpath = NULL;
- dirpath = g_file_get_path (dir);
+ dirpath = ot_gfile_get_path_cached (dir);
enumerator = g_file_enumerate_children (dir, OSTREE_GIO_FAST_QUERYINFO,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
ret = TRUE;
out:
- g_free (dirpath);
return ret;
}
GInputStream *ret = NULL;
int fd;
int flags = O_RDONLY;
- char *path = NULL;
+ const char *path = NULL;
- path = g_file_get_path (file);
+ path = ot_gfile_get_path_cached (file);
#ifdef O_NOATIME
flags |= O_NOATIME;
#endif
ret = (GInputStream*)g_unix_input_stream_new (fd, TRUE);
out:
- g_free (path);
return ret;
}
{
gboolean ret = FALSE;
GMappedFile *mfile = NULL;
- char *path = NULL;
+ const char *path = NULL;
GVariant *ret_variant = NULL;
- path = g_file_get_path (src);
+ path = ot_gfile_get_path_cached (src);
mfile = g_mapped_file_new (path, FALSE, error);
if (!mfile)
goto out;
g_variant_unref (ret_variant);
if (mfile)
g_mapped_file_unref (mfile);
- g_free (path);
return ret;
}
guint32 type;
const char *name;
char buf[1];
- char *child_path = NULL;
+ const char *child_path = NULL;
GString *child_trimmed_path = NULL;
GFile *child = NULL;
gsize bytes_written;
goto out;
}
- child_path = g_file_get_path (child);
+ child_path = ot_gfile_get_path_cached (child);
child_trimmed_path = g_string_new (child_path + strlen (basepath));
if (!*(child_trimmed_path->str))
{
out:
g_string_free (child_trimmed_path, TRUE);
child_trimmed_path = NULL;
- g_free (child_path);
child_path = NULL;
g_clear_object (&child);
return ret;
{
FindThreadData *tdata = data;
GError *error = NULL;
- char *path;
+ const char *path;
- path = g_file_get_path (tdata->dir);
+ path = ot_gfile_get_path_cached (tdata->dir);
if (!find (path, tdata->dir, tdata->separator, tdata->out,
tdata->cancellable, &error))
{
g_printerr ("%s", error->message);
g_clear_error (&error);
}
- g_free (path);
g_clear_object (&(tdata->dir));
g_clear_object (&(tdata->out));
return NULL;
GError **error)
{
gboolean ret = FALSE;
- char *dest_path = NULL;
- char *src_path = NULL;
+ const char *dest_path = NULL;
+ const char *src_path = NULL;
GError *temp_error = NULL;
GFileInfo *src_fileinfo = NULL;
GFileInfo *dest_fileinfo = NULL;
const char *name;
guint32 type;
- dest_path = g_file_get_path (destination);
- src_path = g_file_get_path (src);
+ dest_path = ot_gfile_get_path_cached (destination);
+ src_path = ot_gfile_get_path_cached (src);
dest_fileinfo = g_file_query_info (destination, OSTREE_GIO_FAST_QUERYINFO,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
ret = TRUE;
out:
- g_free (dest_path);
- g_free (src_path);
g_clear_object (&src_fileinfo);
g_clear_object (&dest_fileinfo);
g_clear_object (&src_enum);
if (!ostree_repo_resolve_rev (repo, branch, FALSE, &branchrev, error))
goto out;
- destpath = g_file_get_path (destination);
+ destpath = g_strdup (ot_gfile_get_path_cached (destination));
if (g_str_has_suffix (destpath, "/"))
destpath[strlen (destpath) - 1] = '\0';
branchpath = g_strconcat (destpath, "-tmp-checkout-", branchrev, NULL);
out:
if (branchf)
rm_rf (branchf);
+ g_free (destpath);
g_clear_object (&enumerator);
g_clear_object (&branchf);
g_free (branchrev);
- g_free (destpath);
g_free (branchpath);
return ret;
}